package com.base_java.controller.task;


import com.base_java.common.ServerResponse;
import com.base_java.pojo.Device;
import com.base_java.service.IDeviceService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/device/")
public class DeviceController {

    @Autowired
    private IDeviceService iDeviceService;

    /**
     * 新增设备 RequestBody 使用json传参 使用RequestBody注解来web请求中的body体部分内容,并且通常会将其转换为一个javaBean的对象！
     *
     * @param device Device对象 {@link Device}
     * @return 返回新增是否成功
     */
    @RequestMapping(value = "device_add.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> add(@RequestBody Device device) {
        return iDeviceService.add(device);
    }


    /**
     * 设备列表
     *
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return PageInfo对象
     */
    @RequestMapping(value = "device_list.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<PageInfo> deviceList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                               @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        return iDeviceService.deviceList(pageNum, pageSize);
    }

    /**
     *  删除设备
     * @param hotelId ？ todo 根据设备id删除设备
     * @return 删除是否成功
     */
    @RequestMapping(value = "device_move.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> move(Integer hotelId) {
        return iDeviceService.move(hotelId);
    }

    /**
     *  更新设备信息
     * @param device Device对象{@link Device}
     * @return 更新后是否成功
     */
    @RequestMapping(value = "device_update.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<Device> updateInformation(Device device) {
        return iDeviceService.updateInformation(device);
    }


}
